
#ifndef _BSP_IO_H_
#define _BSP_IO_H_

#include "peripheral.h"

#if 0
typedef enum {
	GPA = (uint8_t)0,
	GPB,
	GPC,
	GPD,
	GPE,
	GPF,
	GPG,
	GP_Max,
}GP_T;

typedef enum {
	Pin0 = (uint8_t)0,
	Pin1 = (uint8_t)1,
	Pin2 = (uint8_t)2,
	Pin3 = (uint8_t)3,
	Pin4 = (uint8_t)4,
	Pin5 = (uint8_t)5,
	Pin6 = (uint8_t)6,
	Pin7 = (uint8_t)7,
	Pin8 = (uint8_t)8,
	Pin9 = (uint8_t)9,
	Pin10 = (uint8_t)10,
	Pin11 = (uint8_t)11,
	Pin12 = (uint8_t)12,	
	Pin13 = (uint8_t)13,
	Pin14 = (uint8_t)14,
	Pin15 = (uint8_t)15,
}Pin_T;

typedef enum {
	Pin_Mode_OUT, 		//output
	Pin_Mode_OD,		//open drain
	Pin_Mode_IN,		//input
	Pin_Mode_AIN,
	Pin_Mode_IPD,
	Pin_Mode_IPU,
	Pin_Mode_AFOD,
	Pin_Mode_AFPP,
}Pin_Mode;
#endif 

typedef uint32_t GP_T;
typedef uint16_t Pin_T;



//	extern GPIO_T* const gpioPorts[GP_Max];

#define BSP_IO_ToPort(port)	(GP_T)(unsigned int)(port)
#define BSP_IO_ToPin(pin)	(Pin_T)(unsigned int)(pin)

#define BSP_IO_Set(gp, pin, state)		\
do {	\
    if(state != 0){GPIO_BOP(gp) = (uint32_t)pin;}		\
	else{GPIO_BC(gp) = (uint32_t)pin;}		\
}while(0)


#if 0
#define BSP_IO_Set(gp, pin, state)		\
	do{    \
		if(RESET != state)GPIO_BOP(gp) = (uint32_t)pin;	\
	    else GPIO_BC(gp) = (uint32_t)pin;	\
	}while(0)
#endif 

#define BSP_IO_Get(gp, pin)			(GPIO_ISTAT(gp)&(pin) ? 1 : 0)

//	#define BSP_IO_Mode(port, pin, mode) do{gpioPorts[port]->MODE = (gpioPorts[port]->MODE & ~(0x3 << (pin << 1))) | (mode << (pin << 1));}while(0)
#if 0
#define BSP_IO_Mode(port, pin, mode) do{ \
	uint32_t __mode = gpioPorts[port]->MODE; \
	uint32_t __pin = pin;						\
	gpioPorts[port]->MODE = (__mode & ~(0x3 << (__pin << 1))) | (mode << (__pin << 1)); \
	}while(0)
#endif 

void BSP_IO_Init(GP_T gp, Pin_T pin, uint32_t mode);
void BSP_IO_SetMode(GP_T gp, Pin_T pin, uint32_t mode);
//	void BSP_IO_EnableInt(GP_T gp, Pin_T pin, uint32_t attribs);
//	void BSP_IO_DisableInt(GP_T gp, Pin_T pin);


#endif


